/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.validator;

import com.minierp.bean.LoginBean;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

public class LoginBeanValidator implements Validator {
	public boolean supports(Class clazz) {
		return LoginBean.class.isAssignableFrom(clazz);
	}

	public void validate(Object obj, Errors errors) {
		LoginBean form = (LoginBean) obj;
		if (form.getUserName() != null && !form.getUserName().trim().equals("")) {
			if (form.getPassword() != null
					&& !form.getPassword().trim().equals("")) {
				if (form.getValidateCode() != null
						&& !form.getValidateCode().equals("")) {
					if (form.getRandomCode() == null
							|| !form.getValidateCode().equals(
									form.getRandomCode())) {
						errors.rejectValue("validateCode", "", "『验证码』错误");
					}
				} else {
					errors.rejectValue("validateCode", "", "请输入『验证码』");
				}
			} else {
				errors.rejectValue("password", "", "请输入『密码』");
			}
		} else {
			errors.rejectValue("userName", "", "请输入『帐号』");
		}

	}
}